const baseUrl = 'https://exam.lrltd.cn'
const api = function(url, method = 'GET', data) {
  url = baseUrl + url;
  return new Promise((resolve, reject) =>{
    wx.showNavigationBarLoading();
    wx.request({
      url,
      header: {
        'content-type':'application/json',
        'Authorization': wx.getStorageSync('Authorization')
      },
      method,
      data,
      success(res) {
        if (res.data.code !== 20000) {
          reject('网络出错')
        }
        resolve(res.data)
      },
      fail(res) {
        reject(res.errMsg)
      },
      complete(res) {
        wx.hideNavigationBarLoading();
      }
    })
  })
}

module.exports = {
  api
}


// 'content-type': method === 'GET' ? 'application/json' : 'application/x-www-form-urlencoded',